package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.R;

import java.util.ArrayList;

public class EventChooseListAdapter extends BaseAdapter {

    private ArrayList<String> mData;
    private Context mContext;
    private int mSelectedPosition;

    public EventChooseListAdapter(Context context, ArrayList<String> mData) {
        this.mData = mData;
        this.mContext = context;
    }


    @Override
    public int getCount() {

        return mData.size();
    }

    public void setSelectedPosition(int position) {
        mSelectedPosition = position;
        notifyDataSetChanged();
    }

    @Override
    public String getItem(int position) {

        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.text_event_item, null);
            holder.ivChoose = (ImageView) convertView.findViewById(R.id.event_choose_which);
            holder.tvItem = (TextView) convertView.findViewById(R.id.text_event_desc);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == mSelectedPosition) {
            holder.ivChoose.setVisibility(View.VISIBLE);
        } else {
            holder.ivChoose.setVisibility(View.GONE);

        }
        holder.tvItem.setText(mData.get(position));
        return convertView;
    }

    private class ViewHolder {
        ImageView ivChoose;
        TextView tvItem;
    }


}
